<?php

namespace Addons\OaSystem\Model;
use Think\Model;

/**
 * OaSystem模型
 */
class OaEmployeeModel extends Model{

    public function addEmployee($data){
        if ($data == NULL){
            return null;
        }
        $t_map['appid'] = $data['appid'];
        $t_map['account'] = $data['account'];
        $same_account = $this->where($t_map)->select();
        if (count($same_account) >= 1) {
            if($same_account[0]['idnum'] != $data['idnum']){
                return false;
            }
        }

        $map['appid'] = $data['appid'];
        $map ['name'] = $data['name'];
        $map ['emp_no'] = $data['emp_no'];
        $emp = $this->where($map)->find();
        if ($emp != NULL) {
            if($emp['emp_no'] != $data['emp_no'] ||
                $emp['account'] != $data['account'] ||
                $emp['password'] != $data['password'] ||
                $emp['dept_id'] != $data['dept_id'] ||
                $emp['birthday'] != $data['birthday'] ||
                $emp['duty_id'] != $data['duty_id'] ||
                $emp['office_tel'] != $data['office_tel'] ||
                $emp['mobile_list'] != $data['mobile_list'] ||
                $emp['adminLvl_id'] != $data['adminLvl_id'] ||
                $emp['is_left'] != $data['if_left'])
            {
                $data['update_time'] = $data['time'];
                $res = $this->where($map)->save($data);
                return $res;
            } else
                return true;
        } else {
            $data['create_time'] = $data['time'];
            $res = $this->add ( $data );
            return $res;
        }
    }
}
